package com.hadoop.demo.mapreduce.flowcount;

import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * =================================
 * <p>
 * Created by cjj on 18-10-8.
 * <p>
 * 描述:
 */

public class FlowSumMapper extends Mapper<LongWritable,Text,Text,FlowBean> {


    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //super.map(key, value, context);
        //take line data
        String line = value.toString();
        //split key
        String[] fields = StringUtils.split(line,"\t");
        //phonenumber、up、down position
        String phoneNumber = fields[1];
        long up_flow = Long.parseLong(fields[7]);
        long down_flow = Long.parseLong(fields[8]);

        context.write(new Text(phoneNumber), new FlowBean(phoneNumber,up_flow,down_flow));
    }
}
